/* eslint-disable no-multi-spaces */
import moment from 'moment'
let weekTime = moment(new Date())
  .subtract('days', 6)
  .format('YYYY-MM-DD')
let now = moment(new Date()).format('YYYY-MM-DD')
const state = {
  resetData: false,
  chart: {},
  changeArea: true,
  editDataShow: false,
  drawFlag: false,
  loading: false,
  index: 1,
  newRender: true,
  drop: false,
  shadeDisplay: true,
  theme: 'default-theme',
  startTime: '',
  endTime: '',
  oldFormData: {
    statSource: 1,
    statSourceId: [],
    file: '',
    chartsTitle: '',
    key: [], // 关键词
    select: [], // 选择关键词,eg:标题
    fontType: '0', // 简繁体
    keywords: [], // 3-标题或正文-123   selectid-选择id对应的内容-关键词，增加关键词
    keywords1: '', // 3-标题或正文-123   selectid-选择id对应的内容-关键词，未增加关键词
    type: [], // 情感属性
    typeNode: [],
    from: ['1', '2', '3', '4', '5', '9', '11'], // 来源
    fromNode: ['网媒', '论坛', '博客', '平煤', 'APP', '微信', '微博'],
    issuedata: [],
    issuedataStart: weekTime + ' 00:00:00', // 发布时间
    issuedataEnd: now + ' 23:59:59',
    indexesdata: [],
    indexesdataStart: '', // 索引时间
    indexesdataEnd: '',
    username: '', // 用户名
    usernameLable: '',
    platform: '', // 平台
    platformLable: '',
    gather: '0', // 采集配置全部来源
    gatherLable: '全部',
    hot: '', // 热点
    hotLable: '',
    site: '0', // 选择发布状态
    siteLable: '未删',
    err: [], // 选择错误类型
    errLable: [],
    sensitive: '0', // 选择敏感类型
    sensitiveLable: '非敏感',
    territory: [], // 请选择地域
    territory1: [], // 请选择内容地域
    territory1Node: [],
    territory2: [], // ICP地域
    territory2Node: [],
    territory3: [], // 泛主题地域
    territory3Node: [],
    territory4: [], // 确主题地域
    territory4Node: [],
    title: '1', // 标题劫持
    titleLable: '全部',
    condition: '1', // 来源条件
    conditionLable: '全部',
    affiliation: '', // 站点归属
    affiliationLable: '',
    module: [], // 模块
    moduleNode: [], // 模块
    company: [], // 公司
    companyNode: [], // 公司
    production: [], // 产品
    productionNode: [], // 产品当前选中节点
    people: [], // 人物
    peopleNode: [], // 人物
    infoSite: [], // 信息采集位置
    infoSiteNode: [],
    mediaWeightFrom: '', // 媒体权重
    mediaWeightTo: '',
    mediaWeight: [],
    siteInfor: [], // 站点信息
    siteInforNode: [], // 站点信息
    sepcialSite: [], // 特殊站点
    sepcialSiteNode: [],
    weoboUser: [], // 用户类型
    weoboUserNode: [],
    sepcialWeioboUser: [], // 特殊微博用户
    sepcialWeioboUserNode: [],
    area: [],
    areaId: [],
    websType: '1' // 站点列表树的查询列表
  },
  formData: {},
  downloadData: {
    territory1: [], // 请选择内容地域
    territory1Node: [],
    territory2: [], // ICP地域
    territory2Node: [],
    territory3: [], // 泛主题地域
    territory3Node: [],
    territory4: [], // 确主题地域
    territory4Node: []
  },
  chartsCondition: {},
  oldData: [],
  chartData: [],
  controlWays: false,
  oldchartsConData: {
    autoFit: true,
    svgColor: '#eee', // 词云图背景颜色
    arrayData: [],
    theme: 'default-theme', // 图表主题自定义名称
    themeColor: [
      // 图表主题色
      '#5867C3',
      '#FF525E',
      '#C36B9E',
      '#FFA900',
      '#FFCE44',
      '#06C5DC',
      '#039DAF',
      '#71E199'
    ],
    chartsMaxWidth: 0, // 图表的最大宽度
    chartsMaxHeight: 0, // 图表的最大高度
    chartName: '', // 图表类型名称
    name: '', // 图表名称
    title: '', // 主标题
    titleName: '', // 图形下面得标题
    subtitle: '', // 副标题
    titleLocation: 'top', // 标题位置
    legend: '0', // 是否显示图例
    legendPosition: 'bottom', // 图例位置  1--底部  2--顶部 3--左侧 4--右侧
    legendOffsetX: 0, // 图例 x 方向的偏移
    legendOffsetY: 0, // 图例 Y 方向的偏移
    percent: '1', // 饼图是否显示百分比
    precision: 2, // 精确度
    canvasWidth: 0, // 柱状图宽度
    canvasHeight: 0, // 柱状图高度
    canvasTopPad: 150, // 柱状图上间距
    canvasRightPad: 150, // 柱状图右间距
    canvasBottomPad: 100, // 柱状图下间距
    canvasLeftPad: 150, // 柱状图左间距
    tickCount: '', // 柱状图横坐标刻度格数
    dateFormat: '2', // 时间格式 '1'---YYYY年MM月DD日 HH时 '2'--YYYY/MM/DD HH '3'--YYYY/MM/DD HH1 HH2 HH3……
    valueUnit: '单位/篇', // 数值单位
    timeUnit: '单位/年', // 时间轴单位
    timeUnitFlag: false,
    showYear: '1', // 是否显示年
    showMonth: '1', // 是否显示月
    showDay: '1', // 是否显示日
    showHour: '1', // 是否显示小时
    oldType: '', // 上一次的图表类型
    type: '', // 图表类型 1：饼图，2：柱图，3：折线图，4：地图，5：词云图
    type1: '', // 具体图表类型
    oldWays: '', // 上一次的图表类型
    ways: '', // 统计类型 1：媒体类型，2：发布时间，3：站点发布量，4：舆情地图，5：情感，6：关键词
    unit: '1', // 单位，1--天， 2--小时 3--月
    mergeNum: 1, // 聚合默认数量
    keywordNum: 20, // 关键词默认数量
    siteCount: 20, // 发布量默认数量
    bagShow: '0', // 词云图背景手否显示
    svg: 'cloud1', // 默认适量背景图名称
    repeat: '1', // 词云图是否重复repeat
    statAreaAttr: '380', // 默认区域
    cityShow: '1', // 是否显示省市
    citySize: {
      // 各省市对应的长宽
      北京: [762, 772]
    },
    areaRange: [
      // 地图图例范围
      { id: 0, start: 0, end: 100000, text: '低热' },
      { id: 1, start: 100000, end: 500000, text: '较高热' },
      { id: 2, start: 500000, end: 1000000, text: '高热' },
      { id: 3, start: 1000000, end: 2000000, text: '最高热' }
    ],
    thumbnail: '1', // 九段线缩略图是否显示，'1'--显示 '0'--不显示
    textSize: 18, // 文字大小
    offset: 20, // 文字偏移量
    bOffset: {}, // 饼状图文本偏移
    text: '', // 饼状图对应设置文本偏移的lable
    layout: 'distribute' // 文字重叠处理
  },
  themeColor: {
    'define-theme1': [
      '#5867C3',
      '#FF525E',
      '#C36B9E',
      '#FFA900',
      '#FFCE44',
      '#06C5DC',
      '#039DAF',
      '#71E199'
    ],
    'define-theme2': ['#5867C3'],
    'default-theme': [
      '#5867C3',
      '#FF525E',
      '#C36B9E',
      '#FFA900',
      '#FFCE44',
      '#06C5DC',
      '#039DAF',
      '#71E199'
    ],
    'default-theme1': [
      '#284a75',
      '#40559d',
      '#1f709e',
      '#237a99',
      '#65bbbf',
      '#51b7d7',
      '#86c7d6',
      '#9ca8c0'
    ],
    'default-theme2': [
      '#3d535b',
      '#748c5f',
      '#4bb189',
      '#4eaf6c',
      '#2d986d',
      '#5fb05a',
      '#a1c438',
      '#afce73'
    ],
    'default-theme3': [
      '#7e5831',
      '#a75840',
      '#bc6327',
      '#a08844',
      '#EBAC2F',
      '#f5c53a',
      '#e9e050',
      '#d4dc64'
    ],
    'default-theme4': [
      '#912531',
      '#b0282a',
      '#a91e2f',
      '#d7727a',
      '#E83A37',
      '#C45564',
      '#E5886B',
      '#EEAAA1'
    ],
    'default-theme5': [
      '#262626',
      '#404040',
      '#595959',
      '#7F7F7F',
      '#A6A6A6',
      '#BFBFBF',
      '#D9D9D9',
      '#F2F2F2'
    ]
  },
  chartsConData: {},
  areaList: [],
  switchData: '1',
  oldWays: '',
  resetFormData: false
}
function splitTime(startDate, endDate, dt) {
  let startTime = new Date(startDate.replace(/-/g, '/'))
  let endTime = new Date(endDate.replace(/-/g, '/'))
  let m1 = moment(startTime)
  let m2 = moment(endTime)
  let day = m2.diff(m1, dt)
  return day
}
const mutations = {
  // 设置聚合量
  setMergeNum(state) {
    let merg = 1
    switch (Number(state.chartsConData.ways)) {
      case 2:
      case 5:
        switch (Number(state.chartsConData.type)) {
          case 2:
          case 3:
            switch (Number(state.chartsConData.unit)) {
              case 1:
                merg = splitTime(
                  state.chartsCondition.issuedataStart,
                  state.chartsCondition.issuedataEnd,
                  'day'
                )
                break
              case 2:
                merg = splitTime(
                  state.chartsCondition.issuedataStart,
                  state.chartsCondition.issuedataEnd,
                  'hour'
                )
                break
              case 3:
                merg = splitTime(
                  state.chartsCondition.issuedataStart,
                  state.chartsCondition.issuedataEnd,
                  'month'
                )
                break
            }
            break
        }
    }
    console.log(Math.ceil(merg / 8))
    state.chartsConData.mergeNum = Math.ceil(merg / 8)
  },
  // 设置标题
  setTitle(state, payload) {
    switch (state.chartsConData.ways) {
      case '1':
        state.chartsConData.title = '媒体来源:' + state.chartsConData.titleName
        break
      case '2':
        state.chartsConData.title = '发布时间:' + state.chartsConData.titleName
        break
      case '3':
        state.chartsConData.title =
          '站点发布量:' + state.chartsConData.titleName
        break
      case '4':
        state.chartsConData.title = '舆情地图:' + state.chartsConData.titleName
        break
      case '5':
        state.chartsConData.title = '情感:' + state.chartsConData.titleName
        break
      case '6':
        state.chartsConData.title = '关键词:' + state.chartsConData.titleName
        break
    }
  },
  setStoreParams(state, payload) {
    payload.forEach(el => {
      state[el.key] = JSON.parse(JSON.stringify(el.value))
    })
  },
  // 编辑数据中是否清空数据
  setResettdata(state, payload) {
    state.resetData = payload
  },
  setChangeArea(state, payload) {
    state.changeArea = payload
  },
  setEditDataShow(state, payload) {
    state.editDataShow = payload
  },
  setDrawFlag(state, payload) {
    state.drawFlag = !state.drawFlag
  },
  // 设置loading状态
  setLoading(state, payload) {
    state.loading = payload
  },
  // 设置自定义主题色
  setThemeColor(state, payload) {
    state.themeColor['define-theme1'][payload.key] = payload.value
    state.chartsConData.themeColor[payload.key] = payload.value
  },
  // 设置主题色名称
  resetThemeColor(state) {
    state.themeColor['define-theme1'] = state.chartsConData.themeColor
  },
  // 设置索引逐渐递增
  setIndex(state, payload) {
    if (payload) {
      state.index = payload + 1
    } else {
      state.index += 1
    }
  },
  // 设置发布时间
  setTime(state, payload) {
    state[payload.key] = payload.value
  },
  // 设置是否重新渲染
  setRender(state, payload) {
    state.newRender = payload
  },
  // 设置遮罩层
  setshadeDisplay(state, payload) {
    state.shadeDisplay = payload
  },
  // 设置当前编辑数据的tab索引值
  setTabIndex(state, payload) {
    state.statSource = payload
  },
  // 设置原始统计方式
  setOldWays(state, payload) {
    state.oldWays = payload
  },
  // 设置是否重新请求数据
  setSwitchData(state, payload) {
    state.switchData = payload
  },
  //  设置图表绘制的原始数据
  setOldData(state, payload) {
    state.oldData = payload
  },
  getNewFormData(state, payload) {
    for (let i in payload.types) {
      if (
        Object.prototype.toString.call(payload.datas[i]) === '[object Array]'
      ) {
        state.formData[payload.types[i]] = [...payload.datas[i]]
      } else {
        state.formData[payload.types[i]] = payload.datas[i]
      }
    }
  },
  setFormData(state, payload) {
    if (payload) {
      state.formData = {
        ...state.formData,
        ...payload.data
      }
    } else {
      state.formData = Object.assign({}, state.chartsCondition)
    }
  },
  getConditionData(state, payload) {
    if (payload) {
      state.chartsCondition = Object.assign({}, payload.data)
    } else {
      state.chartsCondition = Object.assign({}, state.formData)
    }
  },
  clearData(state, payload) {
    payload.forEach(item => {
      state[item.key] = JSON.parse(JSON.stringify(item.value))
    })
    state.resetFormData = !state.resetFormData
  },
  // 设置绘制图表后的数据
  setChartsData(state, payload) {
    let newData = []
    if (
      Object.prototype.toString.call(payload.data) === '[object Object]' &&
      payload.data['APP采集']
    ) {
      payload.data['APP'] = payload.data['APP采集']
      delete payload.data['APP采集']
    }
    state.oldData = payload.data
    switch (state.chartsConData.ways) {
      case '1':
        switch (state.chartsConData.type1) {
          case 'b1':
          case 'b2':
          case 'b3':
          case 'b4':
          case 'b5':
          case 'b6':
          case 'b7':
          case 'z1':
          case 'z4':
            newData = []
            for (let i in payload.data) {
              newData.push({
                label: i,
                value: payload.data[i]
              })
            }
            state.chartData = newData
            break
          case 'z2':
            newData = []
            for (let i in payload.data) {
              newData.push({
                name: i,
                媒体来源: payload.data[i]
              })
            }
            state.chartData = newData
            break
          case 'z3':
            newData = []
            for (let i in payload.data) {
              newData.push({
                name: i,
                year: '媒体来源',
                value: payload.data[i]
              })
            }
            state.chartData = newData
            break
        }
        break
      case '2':
        switch (state.chartsConData.type1) {
          case 'z1':
          case 'z4':
          case 'l2':
            newData = []
            let list = payload.data
            for (let i in list.dateArr) {
              newData.push({
                label: list.dateArr[i],
                value: list.allData[i]
              })
            }
            state.chartData = newData
            break
          case 'z2':
            newData = []
            list = payload.data
            for (let i in list.dataMap) {
              let item = list.dataMap[i]
              newData.push({
                name: i
              })
              for (let j in list.dateArr) {
                let date = list.dateArr[j]
                newData[newData.length - 1][date] = item[j]
              }
            }
            state.chartData = newData
            break
          case 'z3':
            newData = []
            list = payload.data
            for (let i in list.dataMap) {
              let item = list.dataMap[i]
              for (let j in list.dateArr) {
                newData.push({
                  name: i,
                  year: list.dateArr[j],
                  value: item[j]
                })
              }
            }
            state.chartData = newData
            break
          case 'l1':
            newData = []
            list = payload.data
            for (let i in list.dataMap) {
              let item = list.dataMap[i]
              for (let j in list.dateArr) {
                newData.push({
                  name: i,
                  year: list.dateArr[j],
                  value: item[j]
                })
              }
            }
            state.chartData = newData
            break
        }
        break
      case '3':
      case '6':
        switch (state.chartsConData.type1) {
          case 'c1':
            newData = []
            let list = payload.data
            for (let i in list) {
              newData.push({
                name: i,
                value: list[i]
              })
            }
            state.chartData = newData
            break
        }
        break
      case '4':
        switch (state.chartsConData.type1) {
          case 'd1':
          case 'd2':
            newData = payload.data
            state.chartData = newData
            if (state.areaList.length === 0) {
              state.areaList = payload.data
            }
            break
        }
        break
      case '5':
        switch (state.chartsConData.type) {
          case '1':
            if (!payload.data.hasOwnProperty('dateArr')) {
              newData = []
              for (let i in payload.data) {
                newData.push({
                  label: i,
                  value: payload.data[i]
                })
              }
              state.chartData = newData
            } else {
              state.chartData = []
            }
            break
          case '2':
          case '3':
            switch (state.chartsConData.type1) {
              case 'z1':
              case 'z4':
                newData = []
                let list = payload.data
                for (let i in list.dateArr) {
                  newData.push({
                    label: list.dateArr[i],
                    value: list.allData[i]
                  })
                }
                state.chartData = newData
                break
              case 'z2':
                newData = []
                list = payload.data
                for (let i in list.dataMap) {
                  let item = list.dataMap[i]
                  newData.push({
                    name: i
                  })
                  for (let j in list.dateArr) {
                    let date = list.dateArr[j]
                    newData[newData.length - 1][date] = item[j]
                  }
                }
                state.chartData = newData
                break
              case 'z3':
              case 'l1':
                newData = []
                list = payload.data
                for (let i in list.dataMap) {
                  let item = list.dataMap[i]
                  for (let j in list.dateArr) {
                    newData.push({
                      name: i,
                      year: list.dateArr[j],
                      value: item[j]
                    })
                  }
                }
                state.chartData = newData
                break
            }
            break
        }
        break
    }
  },
  // 设置绘制图表后的数据
  setChartsData1(state, payload) {
    state.chartData = payload.data
  },
  setControlWays(state, payload) {
    state.controlWays = !state.controlWays
    state.chartsConData = Object.assign(state.chartsConData, payload)
  },
  // 设置绘制图表后的数据
  setchangeChartsData(state, payload) {
    state.chartData = payload
  },
  // 设置右侧选定条件
  setChartsConData(state, payload, flag) {
    state.chartsConData = Object.assign(state.chartsConData, payload)
  },
  setNewFormData(state, payload) {
    state.formData = Object.assign(state.formData, payload)
  }
}

const actions = {
  // 重新获取数据绘制图表
  dispatchNewData({ commit, state }, payload) {
    return new Promise((resolve, reject) => {
      let keywords = []
      state.chartsCondition.keywords.forEach(item => {
        item = item.split(':')
        keywords.push({
          keyword: item[2],
          matchScope: Number(item[0])
        })
      })
      if (state.chartsCondition.keywords1) {
        let obj = state.chartsCondition.keywords1.split(':')
        keywords.push({
          keyword: obj[2],
          matchScope: Number(obj[0])
        })
      }
      let id = ''
      if (JSON.parse(localStorage.getItem('userlist'))) {
        id = JSON.parse(localStorage.getItem('userlist')).id
      }
      let formData
      switch (Number(state.chartsCondition.statSource)) {
        case 1:
        case 2:
        case 3:
          formData = {}
          if (
            Number(state.chartsConData.ways) === 2 ||
            Number(state.chartsConData.ways) === 5
          ) {
            formData.mergeNum = Number(state.chartsConData.mergeNum)
          }
          if (Number(state.chartsConData.ways) === 3) {
            formData.siteCount = Number(state.chartsConData.siteCount)
          }
          if (Number(state.chartsConData.ways) === 4) {
            formData.statAreaAttr = Number(state.chartsConData.statAreaAttr)
          }
          if (Number(state.chartsConData.ways) === 6) {
            formData.keywordNum = state.chartsConData.keywordNum
          }
          formData.userId = id
          formData.chartType = Number(payload.type)
          formData.statType = Number(state.chartsConData.ways)
          formData.timeStatType = Number(state.chartsConData.unit)
          formData.statSource = Number(state.chartsCondition.statSource)
          break
        case 4:
          formData = new FormData()
          if (
            Number(state.chartsConData.ways) === 2 ||
            Number(state.chartsConData.ways) === 5
          ) {
            formData.append('mergeNum ', Number(state.chartsConData.mergeNum))
          }
          if (Number(state.chartsConData.ways) === 3) {
            formData.append('siteCount ', Number(state.chartsConData.siteCount))
          }
          if (Number(state.chartsConData.ways) === 4) {
            formData.append(
              'statAreaAttr ',
              Number(state.chartsConData.statAreaAttr)
            )
          }
          if (Number(state.chartsConData.ways) === 6) {
            formData.append('keywordNum ', state.chartsConData.keywordNum)
          }
          formData.append('userId', id)
          formData.append('chartType', Number(payload.type))
          formData.append('statType', Number(state.chartsConData.ways))
          formData.append('timeStatType', state.chartsConData.unit)
          formData.append(
            'statSource',
            Number(state.chartsCondition.statSource)
          )
          break
      }
      if (Number(state.chartsCondition.statSource) === 1) {
        formData.beginDatePubTime = state.chartsCondition.issuedataStart
        formData.endDatePubTime = state.chartsCondition.issuedataEnd
        if (keywords.length > 0) {
          formData.keywords = keywords
        }
        if (state.chartsCondition.from.length > 0) {
          formData.articleType = state.chartsCondition.from.join(',')
        }
        if (state.chartsCondition.type.length > 0) {
          formData.ownPlusAttrArr = state.chartsCondition.type.join(',')
        }
        if (state.chartsCondition.territory1.length > 0) {
          formData.areaAttr = state.chartsCondition.territory1.join(',')
        }
        if (state.chartsCondition.territory2.length > 0) {
          formData.icpIdAttr = state.chartsCondition.territory2.join(',')
        }
        if (state.chartsCondition.territory3.length > 0) {
          formData.panTopicAreaIds_is = state.chartsCondition.territory3.join(
            ','
          )
        }
        if (state.chartsCondition.territory4.length > 0) {
          formData.topicAreaIds_is = state.chartsCondition.territory4.join(',')
        }
        if (state.chartsCondition.module.length > 0) {
          formData.moduleAttr = state.chartsCondition.module.join(',')
        }
        if (state.chartsCondition.company.length > 0) {
          formData.companyAttr = state.chartsCondition.company.join(',')
        }
        if (state.chartsCondition.production.length > 0) {
          formData.companyProductAttr = state.chartsCondition.production.join(
            ','
          )
        }
        if (state.chartsCondition.people.length > 0) {
          formData.peopleAttr = state.chartsCondition.people.join(',')
        }
        if (state.chartsCondition.infoSite.length > 0) {
          formData.positionAttr = state.chartsCondition.infoSite.join(',')
        }
        let arr = state.chartsCondition.siteInfor.concat(
          state.chartsCondition.sepcialSite
        )
        if (arr.length > 0) {
          formData.websiteId = arr.join(',')
        }
        if (state.chartsCondition.indexesdataStart !== '') {
          formData.beginDateCreateTime = state.chartsCondition.indexesdataStart
        }
        if (state.chartsCondition.indexesdataEnd !== '') {
          formData.endDateCreateTime = state.chartsCondition.indexesdataEnd
        }
        if (state.chartsCondition.title !== '') {
          formData.titleStatus = Number(state.chartsCondition.title)
        }
        if (state.chartsCondition.condition !== '') {
          formData.sourceCondition = Number(state.chartsCondition.condition)
        }
        if (state.chartsCondition.fontType !== '') {
          formData.fontType = Number(state.chartsCondition.fontType)
        }
        if (state.chartsCondition.username !== '') {
          formData.editor = Number(state.chartsCondition.username)
        }
        if (state.chartsCondition.platform !== '') {
          formData.productId = Number(state.chartsCondition.platform)
        }
        if (state.chartsCondition.hot !== '') {
          formData.hotEventId = Number(state.chartsCondition.hot)
        }
        if (state.chartsCondition.gather !== '') {
          formData.serviceId = Number(state.chartsCondition.gather)
        }
        if (state.chartsCondition.mediaWeightFrom !== '') {
          formData.minmediaweight = state.chartsCondition.mediaWeightFrom
        }
        if (state.chartsCondition.mediaWeightTo !== '') {
          formData.maxmediaweight = state.chartsCondition.mediaWeightTo
        }
        if (state.chartsCondition.site !== '') {
          formData.delFlag = Number(state.chartsCondition.site)
        }
        if (state.chartsCondition.err !== '') {
          formData.errType = state.chartsCondition.err.join(',')
        }
        if (state.chartsCondition.sensitive !== '') {
          formData.mgType = Number(state.chartsCondition.sensitive)
        }
      }
      if (Number(state.chartsCondition.statSource) === 2) {
        formData.subclassfolderid = state.chartsCondition.statSourceId.join(',')
      }
      if (Number(state.chartsCondition.statSource) === 4) {
        formData.append('file', state.chartsCondition.file)
      }
      let config = {}
      switch (Number(state.chartsCondition.statSource)) {
        case 1:
        case 2:
        case 3:
          config = {
            headers: {
              'Content-Type': 'application/json;charset=UTF-8'
            }
          }
          payload.axios
            .post('/chart/queryChartData', formData, config)
            .then(res => {
              if (res.status === 200) {
                let result = res.data.result
                if (res.data.message === '成功') {
                  if (
                    !res.data.result ||
                    JSON.stringify(res.data.result) === '{}'
                  ) {
                    let obj = {
                      message: '没有数据',
                      type: 'info'
                    }
                    payload.vm.$message({ ...state.tipsParams, ...obj })
                    commit('setshadeDisplay', true)
                    commit('setLoading', false)
                  }
                  commit('setSwitchData', '0')
                  commit('setChartsData', {
                    data: result
                  })
                  resolve(result)
                } else {
                  commit('setSwitchData', '1')
                  let obj = {
                    message: '获取数据失败',
                    type: 'info'
                  }
                  payload.vm.$message({ ...state.tipsParams, ...obj })
                }
              } else {
                let obj = {
                  message: '超时',
                  type: 'info'
                }
                payload.vm.$message({ ...state.tipsParams, ...obj })
              }
            })
          break
        case 4:
          config = {
            headers: {
              'content-type': 'multipart/form-data'
            }
          }
          payload.axios
            .post('/chart/queryChartDataExcel', formData, config)
            .then(res => {
              if (res.status === 200) {
                let result = res.data.result
                if (res.data.message === '成功') {
                  if (!res.data.result) {
                    let obj = {
                      message: '没有数据',
                      type: 'info'
                    }
                    result = []
                    payload.vm.$message({ ...state.tipsParams, ...obj })
                    commit('setshadeDisplay', true)
                  }
                  commit('setSwitchData', '0')
                  commit('setChartsData', {
                    data: result
                  })
                  resolve(result)
                } else {
                  let obj = {
                    message: '获取数据失败',
                    type: 'info'
                  }
                  payload.vm.$message({ ...state.tipsParams, ...obj })
                  commit('setSwitchData', '1')
                }
              } else {
                let obj = {
                  message: '超时',
                  type: 'info'
                }
                payload.vm.$message({ ...state.tipsParams, ...obj })
              }
            })
          break
      }
    }).catch(err => {
      console.log(err)
    })
  }
}

const getters = {}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
